/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.struts.unittests;

import java.util.List;

import junit.framework.TestCase;

import opiam.admin.faare.PropertiesManager;
import opiam.admin.faare.exception.ServiceException;
import opiam.admin.faare.service.UserContext;
import opiam.admin.faare.service.services.StandardService;
import opiam.admin.faare.service.services.references.ReferenceElement;
import opiam.admin.faare.struts.service.StrutsService;
import opiam.admin.faare.struts.unittests.javabeans.UserForm;


/**
 * @author triyanto
 *
 */
public class StrutsServiceTest extends TestCase
{
    /** DOCUMENT ME */
    private UserContext userContext = new UserContext();

    /**
     * Creates a new StrutsServiceTest object.
     *
     * @param arg0 DOCUMENT ME!
     */
    public StrutsServiceTest(String arg0)
    {
        super(arg0);
        PropertiesManager.getInstance();

        try
        {
            StandardService.logon("paul.auster", "matahari", userContext);
        }
        catch (ServiceException e)
        {
            e.printStackTrace();
            throw new RuntimeException("StrutsServiceTest constructor error");
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @param args DOCUMENT ME!
     */
    public static void main(String[] args)
    {
        junit.textui.TestRunner.run(StrutsServiceTest.class);
    }

    /**
     * DOCUMENT ME!
     */
    public void testGetSearchArgument()
    {
        UserForm userForm = new UserForm();
        userForm.setSn("auster");
        userForm.setSn_op("13");
        userForm.setGivenname("paul");

        try
        {
            List args = StrutsService.getSearchArgument("personSearch",
                    userForm, userContext);
        }
        catch (ServiceException e)
        {
            e.printStackTrace();
            assertTrue(false);
        }
    }

    /**
     * DOCUMENT ME!
     */
    public void testGetOperatorsList()
    {
        try
        {
            List args = StrutsService.getOperatorsList("search_sn");
            StringBuffer buf = new StringBuffer();
            buf.append("   List components of refList = ");
            buf.append(System.getProperty("line.separator"));

            java.util.Iterator it = args.iterator();

            ReferenceElement elt = null;

            while (it.hasNext())
            {
                elt = (ReferenceElement) it.next();
                buf.append("   ...");
                buf.append(elt.getLabel());
                buf.append(" = ");
                buf.append(elt.getValue());
                buf.append(System.getProperty("line.separator"));
            }

            System.out.println("testGetOperatorsList result = ");
            System.out.println(buf.toString());
        }
        catch (Exception e)
        {
            e.printStackTrace();
            assertTrue(false);
        }
    }
}
